<template>
	<view class="content">
		<view class="tabs">
			<view class="tab" :class="{active:k == tabsIndex}" @click="changeTabsIndex(k)" v-for="(v,k) in tabs">
				{{v.name}}
			</view>
		</view>
		<view class="list flex column">
			<view class="list-item flex align-center just-between" v-for="(v,k) in list" @click="edit(v)">
				<view class="list-item-left flex align-center flex-1">
					<image :src="$getImageURL(v.image)"></image>
					<view class="flex column flex-1">
						<view class="title">{{v.name}}</view>
						<view v-if="v.state == 1" class="text-green">通过</view>
						<view v-else class="text-gray">待审</view>

						<view class="item-content flex-1">{{v.content}}</view>
						<view class="text-gray">申请时间：{{v.createtime}}</view>
					</view>
				</view>
				<image class="del-img" @click.stop="del(k)" :src="$staticImagePath('/common/delete1.png')" />
			</view>
		</view>
		<wanl-empty v-if="!list.length"></wanl-empty>
		<view class="btn" @click="add()">添加品牌</view>
	</view>
</template>

<script>
	import {
		getBrandList,
		delBrand
	} from '@/API/business.js'
	export default {
		data() {
			return {
				tabs: [{
					name: '全部',
					id: '',
				}, {
					name: '待审',
					id: 0,
				}, {
					name: '通过',
					id: 1,
				}],
				tabsIndex: 0,
				list: []
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList() {
				let state = this.tabs[this.tabsIndex].id
				let data = {
					is_self: 1
				}
				if (state !== '') {
					data.state = state
				}
				getBrandList(data).then(res => {
					this.list = res.data
				})
			},
			add(ids = 0) {
				uni.navigateTo({
					url: './detail'
				})
			},
			edit(item) {
				uni.navigateTo({
					url: './detail?data=' + JSON.stringify(item)
				})
			},
			del(index) {
				uni.showModal({
					title: '确认删除？',
					success: res => {
						if (res.confirm) {
							delBrand({
								ids: this.list[index].id
							}).then(res => {
								this.list.splice(index, 1);
							})
						}
					}
				})
			},
			changeTabsIndex(index) {
				this.tabsIndex = index
				this.getList()
			}
		}
	}
</script>

<style lang="less" scoped>
	.content {
		padding: 120rpx 20rpx 20rpx;

		.tabs {
			display: flex;
			justify-content: space-around;
			align-items: center;
			height: 100rpx;
			position: fixed;
			top: 0rpx;
			left: 0;
			width: 750rpx;
			background-color: #F6F6F6;
			padding-bottom: 20rpx;
			z-index: 10;

			.tab {
				position: relative;
			}

			.tab.active::before {
				content: '';
				position: absolute;
				width: 30rpx;
				height: 6rpx;
				background: linear-gradient(90deg, #DD551B, #F49355);
				border-radius: 3rpx;
				bottom: -20rpx;
				left: 0;
				right: 0;
				margin: auto
			}
		}

		.list {
			gap: 20rpx;

			&-item {
				padding: 20rpx;
				border-radius: 10rpx;
				background-color: #fff;

				>view {
					gap: 20rpx;
					padding-left: 20rpx;
				}

				&-left {
					gap: 20rpx;

					>image {
						width: 140rpx;
						height: 140rpx;
					}

					>view {
						gap: 20rpx;
					}

					.item-content {
						overflow: hidden;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						text-overflow: ellipsis;
						white-space: normal;
						padding-right: 40rpx;
						line-height: 40rpx;
					}
				}
			}
		}

		.del-img {
			width: 30rpx;
			height: 30rpx;
		}

		.btn {
			position: fixed;
			bottom: 30rpx;
			left: 0;
			right: 0;
			margin: auto;
			width: 610rpx;
			height: 92rpx;
			line-height: 92rpx;
			text-align: center;
			background: linear-gradient(90deg, #DD551B, #F49355);
			border-radius: 46rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			font-size: 34rpx;
			color: #FFFFFF;
		}
	}
</style>